# !/usr/usuari/des python
#  -*- coding: utf-8 -*-
"""
@Author        : itgnay
@Time          : 2022/12/24 15:55
@FileName      : 哈希查找.py
@LastEditors   : None
@Editors       : PyCharm
"""

arr = [5, 20, 30, 50, 55]
hash_arr = [0] * 10


def hash(num, hash_arr):
    return num % len(hash_arr)


def create_hash(arr, hash_arr):
    for i in arr:
        p = hash(i, hash_arr)
        while hash_arr[p] != 0:
            p = hash(p + 1, hash_arr)
        hash_arr[p] = i


def hash_search(hash_arr, value):
    p = value % len(hash_arr)
    for i in range(len(hash_arr)):
        if hash_arr[p] != value:
            p = (p + 1) % len(hash_arr)
        else:
            return p


create_hash(arr, hash_arr)
print(hash_arr)
h = hash_search(hash_arr, 50)
print(h)
